package main.Q801_900;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Q891_900 {
    public static void main(String[] args) {
        System.out.println("Question891：");
        System.out.println("Question892：");
        System.out.println("Question893：");
        System.out.println("Question894：");
        System.out.println("Question895：");
        System.out.println("Question896：单调数列");
        System.out.println("Question897：递增顺序搜索树");
        System.out.println("Question898：");
        System.out.println("Question899：");
        System.out.println("Question900：");
    }
}

class Question896{
    public boolean isMonotonic(int[] nums) {
        if (nums.length>2){
            int i=0,flag=0;
            for (i=1;i< nums.length;i++){
                if (nums[i]-nums[i-1]!=0) {
                    flag=nums[i]-nums[i-1]>0 ? 1 : -1;//递增为1，递减为-1
                    break;
                }
            }
            while (i<nums.length){
                if (nums[i]-nums[i-1]>0&&flag==-1) return false;
                else if (nums[i]-nums[i-1]<0&&flag==1) return false;
                i++;
            }
        }
        return true;
    }
}

class Question897{
    public TreeNode increasingBST(TreeNode root) {
        Stack<TreeNode> stack=new Stack<>();
        List<Integer> list=new ArrayList<>();
        while (root!=null||!stack.isEmpty()){
            if (root!=null){
                stack.push(root);
                root=root.left;
            }else {
                root=stack.pop();
                list.add(root.val);
                root=root.right;
            }
        }
        TreeNode vir=new TreeNode(-1),curNode=vir;
        for (int val:list){
            curNode.right=new TreeNode(val);
            curNode=curNode.right;
        }
        return vir.right;
    }
}